import format from '@dfeidao/atom-web/dt/format';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p003 from './p003';
// tslint:disable-next-line:class-name
interface par extends Event {
	page_no: number;
}
export default async function a002(fd: IFeidaoAiBrowserComponent, e: par) {
	// todo
	const res1 = await nodejs<{
		dt: Array<{
			risk_no: string;
			risk_content: string;
			risk_type: string;
			project_no: string;
			project_name: string;
			create_time: number;
			risk_status: number
		}>; c: number
	}>('risk-control/zj-000001/s003', { pn: e.page_no });
	const ren = res1.dt.map((n) => {
		return { ...n, create_time: format(n.create_time, 2) };
	});
	const arr = res1.dt.map((n) => {
		return (n.project_no);
	});
	const res2 = await nodejs<{ dt: Array<{ equip_depart_name: string; project_manager: string; project_no: string }> }>('risk-control/zj-000001/s005', {
		filter: {
			project_nos: arr
		}
	});
	const arr1 = res2.dt.map((n) => {
		return { equip_depart_name: n.equip_depart_name, project_manager: n.project_manager, project_no: n.project_no };
	});
	console.log('arr1', arr1);
	const arr2 = Array();
	for (let i = 0; i < ren.length; i++) {
		for (let x = 0; x < arr1.length; x++) {
			if (ren[i].project_no === arr1[x].project_no) {
				arr2[i] = {
					risk_no:ren[i].risk_no,
					risk_content: ren[i].risk_content,
					risk_type: ren[i].risk_type,
					project_name: ren[i].project_name,
					create_time: ren[i].create_time,
					risk_status: ren[i].risk_status,
					project_manager: arr1[x].project_manager,
					equip_depart_name: arr1[x].equip_depart_name
				};
			}
		}
	}
	if (arr2[0].risk_no == null) {
		arr2[0] = "123123";
	}
	render(fd, arr2, p003, 'p003', "inner");
}
